package transaction_date

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 月初买入日
type MonthBeginningBuyDate struct {
	db *gorm.DB
}

// 初始化
func (m *MonthBeginningBuyDate) Init(db *gorm.DB) {
	m.db = db
}

// 是否是买入日
func (m *MonthBeginningBuyDate) IsBuyDate(transactionDate string) bool {
	var origin int = 0
	var stockNumber *int = &origin
	m.db.Raw("select count(*) from stock_index_month t where t.begin_date=to_date(?,'yyyy-mm-dd')", transactionDate).Scan(&stockNumber)
	if *stockNumber > 0 {
		io.Infoln("日期[%s]是买入日", transactionDate)
		return true
	} else {
		if transactionDate == properties.QuantProperties_.RealtimeBeginDate {
			return true
		} else {
			return false
		}
	}
}
